﻿using DocumentFormat.OpenXml.Lite.Core.Interfaces;
using DocumentFormat.OpenXml.Lite.Core.Office;
using DocumentFormat.OpenXml.Lite.Shared;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.FooterElements
{
    [XmlRoot("sdtContent", Namespace = Constants.WordMain)]
    public class BLSContent : XmlSerializable
    {
        [XmlIgnore]
        public Guid DocumentId { get; set; }

        [Optional]
        [XmlElement("", Namespace = Constants.WordMain)]
        public XmlList<IOfficeElement> Elements { get; set; }

        public BLSContent()
        {
            Elements = new XmlList<IOfficeElement>();
            Elements.Changing += Elements_Changing;
        }

        #region Events

        void Elements_Changing(object sender, ListEventArgs<IOfficeElement> args)
        {
            if (args.Type == ListEventType.Remove)
                return;

            foreach (var p in args.Objects)
            {
                p.DocumentId = this.DocumentId;
            }
        }

        #endregion
    }
}
